<template>
	<view class="z" v-if="cart.length!==0">
		<!-- 收货地址组件 -->
		<my-address></my-address>
		<!-- 购物车商品列表的标题区域 -->
		<view class="cart-title">
			<!-- 左侧的图标 -->
			<view class="cart-icon">
				<uni-icons type="shop" size="18"></uni-icons>
			</view>
			<!-- 右侧的文本-->
			<text class="cart-title-text">购物车</text>
		</view>


		<!-- 循环渲染购物车中的商品上信息 -->
		<uni-swipe-action>
			<block v-for="(goods,i) in cart" :key="i">
				<uni-swipe-action-item :right-options="option" @click='swipeItemClickHandler(goods)'>
					<my-goods @num-change='numChangeHandler' @radio-change='radioChangeHandler' :showNum=true
						:showRadio=true :goods="goods"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>


		<my-settle></my-settle>
	</view>




	<view class="x" v-else>
		<image class="empty-img" src="/static/cart_empty@2x.png"></image>
		<text class="empty-text">空空如也</text>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		mixins: [badgeMix],
		computed: {
			...mapState('m_cart', ['cart'])
		},
		data() {
			return {
				option: [{
					text: '取消',
					style: {
						backgroundColor: '#C00000'
					}
				}]
			};
		},
		methods: {
			...mapMutations('m_cart', ['updataGoodsState', 'updataGoodsNum', 'removeGoodsById']),
			radioChangeHandler(e) {
				this.updataGoodsState(e)
			},
			numChangeHandler(e) {

				this.updataGoodsNum(e)
			},
			swipeItemClickHandler(goods) {
				this.removeGoodsById(goods.goods_id)
			}
		}


	}
</script>

<style lang="scss">
	.z {
		padding-bottom: 50px;
	}

	.cart-title {
		height: 40px;
		display: flex;
		align-items: center;
		padding-left: 5px;
		border-bottom: 1px solid #efefef;

		.cart-title-text {
			margin-left: 5px;
		}
	}

	.x {
		display: flex;
		flex-direction: column;
		align-items: center;

		.empty-img {
			padding-top: 125rpx;
			width: 90px;
			height: 90px;
		}

		.empty-text {
			font-size: 12px;
			color: gray;
			margin: 10px 0;
		}
	}
</style>
